# -*- coding: utf-8 -*-

exit false if ARGV.empty?

class ::String
  def to_win_path
    self.gsub(File::ALT_SEPARATOR, File::SEPARATOR).encode('CP932')
  end
end

def_file = ARGV.first.to_win_path
exit false unless FileTest::exist?(def_file)

require 'yaml'
setting = YAML.load_file(def_file)

require 'erb'
template = ERB.new(setting['template'])

setting['pages'].each do |page_name, config|
  out_file = config['out_file']

  content = config['content']
  
  the_source = template.result(binding)
  
  File.open(out_file, 'wb') do |f|
    f.write(the_source.encode('CP932').gsub("\n", "\r\n"))
  end
end

